from appium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import os,time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Testlogin():
    def setup_method(self):
        os.system('adb root')
        cap={
          "platformName": "Android",
          "deviceName": "emulator-5554",
          "appPackage": "com.kongfz.app",
          "appActivity": "com.kongfz.app.home.mvvm.homepage.HomeActivity",
          "noReset": True
        }
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.driver.implicitly_wait(25)
        sleep(22)

    def teardown_method(self):
        self.driver.quit()
    def test_01(self):
        try:
            self.driver.find_element(By.ID,'com.kongfz.app:id/lav_5').click()
            sleep(12)
            self.driver.find_element(By.ID,'com.kongfz.app:id/et_login_name').send_keys('13847393641')
            sleep(2)
            WebDriverWait(self.driver,15).until(EC.presence_of_element_located((By.ID,'com.kongfz.app:id/et_pwd'))).send_keys("123456Aa")
            sleep(2)
            self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.kongfz.app:id/iconf_privacy")').click()
            sleep(2)
            self.driver.find_element(By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ScrollView/android.widget.LinearLayout/android.view.ViewGroup/android.widget.TextView').click()
            sleep(3)
        except Exception as e:
            print("报错信息:",e)
            t = time.strftime("%Y%m%d%H%M%S",time.localtime())
            self.driver.save_screenshot(t+"loginerror.png")